package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.RatePay;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 缴费率具体缴费人数 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-03-20
 */
public interface RatePayMapper extends BaseMapper<RatePay> {
    @Select({"<script>",
            "SELECT * FROM (",
                "SELECT",
                "*",
                "<if test= 'type != 3'>",
                    ",SUM( num ) AS num_count ",
                "</if>",
                "FROM",
                "rate_pay ",
                "WHERE",
                "year_part = ${yearPart} ",
                "AND quarter_num = ${quarterNum} ",
                "AND lesson_type = 1 ",
                "AND deleted = 0 ",
                "AND `status` IN ( 1, 5, 6 ) ",
                "AND lesson_type = ${lessonType} ",
                "AND add_date = '${addDate}'",
                "AND student_id = ${studentId} ",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                    "AND subjects_id = ${subjectsId} ",
                "</when>",
                "<if test= 'type != 3'>",
                    "GROUP BY subjects_id,school_id ",
                "</if>",
            ") AS t",
            "WHERE 1=1 ",
            "<if test= 'type == 1'>",
                "AND num_count > 1 ",
            "</if>",
            "</script>"})
    public abstract List<RatePay> getRatePayByStudentId(@Param("yearPart") Integer yearPart,
                                                        @Param("quarterNum") Integer quarterNum,
                                                        @Param("lessonType") Integer lessonType,
                                                        @Param("addDate") String addDate,
                                                        @Param("studentId") Long studentId,
                                                        @Param("subjectsId") Long subjectsId,
                                                        @Param("type") Integer type // 1：同一科目报多期，2：不同科目报多期，3查询订单
    );

    @Select({"<script>",
            "SELECT",
            "*",
            "FROM",
            "rate_pay ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND quarter_num = ${quarterNum} ",
            "AND lesson_type = 1 ",
            "AND deleted = 0 ",
            "AND `status` IN ( 1, 5, 6 ) ",
            "AND lesson_type = ${lessonType} ",
            "AND add_date = '${addDate}'",
            "AND student_id = ${studentId} ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "AND subjects_id = ${subjectsId} ",
            "</when>",
            "</script>"})
    public abstract List<RatePay> getRatePayByStudentIdV2(@Param("yearPart") Integer yearPart,
                                                          @Param("quarterNum") Integer quarterNum,
                                                          @Param("lessonType") Integer lessonType,
                                                          @Param("addDate") String addDate,
                                                          @Param("studentId") Long studentId,
                                                          @Param("subjectsId") Long subjectsId,
                                                          @Param("type") Integer type // 1：同一科目报多期，2：不同科目报多期，3查询订单
    );
}
